/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modelo.dao;

import modelo.util.HibernateUtil;
import java.util.List;
import modelo.Curso;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author Leonardo
 */

public class CursoDAO{
    
    private Session session;    
    private Transaction transaction;
    
    public CursoDAO(){                
        HibernateUtil hu = new HibernateUtil(Curso.class);
        session = hu.getSession();
        transaction = session.getTransaction();
    }    
    public void adicionar(Curso c){        
        transaction.begin();
        session.save(c);        
        transaction.commit();
    }
    public void remover(Curso c){        
        transaction.begin();
        session.delete(c);
        transaction.commit();
    }        
    public List<Curso> getListar(){        
        return session.createQuery("select c from Curso as c ").list();
    }
}
